package com.zjjt.dc.modules.srv.controller.lw;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zjjt.dc.common.query.QueryGenerator;
import com.zjjt.dc.common.api.CommonResult;
import com.zjjt.dc.common.util.DESEncryptEntity;
import com.zjjt.dc.common.util.DESEncryptUtil;
import com.zjjt.dc.modules.datacatch.entity.lw.DcCatchDataLwWh;
import com.zjjt.dc.modules.datacatch.service.lw.IDcDataCatchLwWhService;
import com.zjjt.dc.modules.srv.vo.DcCatchDataLwWhVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.hutool.core.bean.BeanUtil;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@Api(tags = "DcCatchDataLwWh 控制器")
@RestController
@RequestMapping("/api/v1/lw/pricecheck")
public class DcPriceCheckController {

    @Autowired
    private IDcDataCatchLwWhService dcCatchDataLwWhService;


    @ApiOperation("分页查询")
    @GetMapping("/whchecklist")
    public CommonResult<IPage<DcCatchDataLwWhVO>> pageQuery(DcCatchDataLwWh entity, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                            HttpServletRequest req) {
        // ...分页查询实现...
        DESEncryptEntity desModel = new DESEncryptEntity();
        desModel.setModel("CBC");
        desModel.setFillCode("pkcs5padding");
        desModel.setOffset("1g6n8n8t");
        desModel.setPassword("1g6n8n8t");
        desModel.setOutType("base64");
        desModel.setOutCharset("utf-8");


        Page<DcCatchDataLwWh> page = new Page<DcCatchDataLwWh>(pageNo, pageSize);
        IPage<DcCatchDataLwWh> pageList = dcCatchDataLwWhService.pageCheckList(page);
        IPage<DcCatchDataLwWhVO> voList = new Page<>();
        List<DcCatchDataLwWhVO> list = CollUtil.newArrayList();
        for(DcCatchDataLwWh item:pageList.getRecords()){
            DcCatchDataLwWhVO vo = new DcCatchDataLwWhVO();
            BeanUtil.copyProperties(item,vo);
            if(StrUtil.isNotEmpty(vo.getReceiverTel())){
                try {
                    vo.setReceiverTel(DESEncryptUtil.decrypt(desModel, vo.getReceiverTel()));
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
            list.add(vo);
        }
        voList.setRecords(list);
        voList.setTotal(pageList.getTotal());
        return CommonResult.success(voList);
    }

}